<?php
/*******************************************************************************
 *
 *  Name: Assignemployeesview
 *
 *  Date: 2012-04-25
 *  
 *  Description: This is where the analyst can assign employees to incidents
 *  
 *  Author: Hayden Waisanen
 *  
 *  Todo:
 *     NONE
 *
 *  Modification History:  
 * 
 *   Date         Name
 *  ----------   --------------
 *  2012-04-25   HAYDEN WAISANEN
 * 
 *****************************************************************************/
?>
<style>
.save {
visibility: hidden;
}
.hidden {
display:none;
}
</style>
<script type="text/javascript">
function submit(UserID)
{
   if($('#'+UserID+'_analyst')[0].checked)
      analystdat='1';
   else
      analystdat='0';
   if($('#'+UserID+'_cr')[0].checked)
   {
      crdat='1';
   }
   else
      crdat='0';
   if($('#'+UserID+'_irteam')[0].checked)
      irteamdat='1';
   else
      irteamdat='0';

   $.ajax({
      type: 'POST',
      url: '../manager/assign/'+UserID+'/',
      success: function(data) {
         $('#'+UserID+'_save').addClass('save');
      },
      data: {
         Analyst:analystdat,
         CustomerRep :crdat,
         IRTeam: irteamdat
         },
      error: function() {
         alert("Unable to attach reports at this time.");
      }
});


}

//Register an event for the submit box
$(document).ready(function() {
     // Handler for .ready() called.
  $('#searchbox').keyup(function() {
     //Make all boxes visible
     search = $(this).val();
     search = search.toUpperCase();
     $('.entry').each(function () {
        contents = this.childNodes[0].innerHTML;
        contents = contents.toUpperCase();
        if((new RegExp(search)).test(contents))
           $(this).removeClass('hidden');
        else 
           $(this).addClass('hidden');
     });
  });
});

function saveAll()
{
   $('.savebuttons').each(function (){
      if(!$(this).hasClass('save'))
         $(this).click();
   });
}


</script>

<div>Search:<form><input id="searchbox" type="text" value="" /></form>
</div>
<div><input id="save_all" type="submit" name="Save All" value="Save All" onclick="saveAll()"/></div>
<table border="2px">
<tr><td>Username</td><td width="100px">Analyst</td><td width="100px">IRTeam</td><td width="100px">Customer Rep</td><td>Submit</td></tr>

<?php 
foreach( $users as $user )
{
   $onclick = " onclick='".'$("#'.$user["UserID"].'_save").removeClass("save")'."' ";
   echo "<tr class='entry'>";
   //Analyst
   echo "<td>".$user['UserID']."</td>";
   echo "<td>";
   echo '<input type="checkbox" id="'.$user["UserID"].'_analyst" name="Analyst"'.$onclick;
   if($user['Analyst'] == '1')
      echo " checked ";
   echo '/>';
//<input type="checkbox" name="option1" value="Milk"> Milk<br>
   //IRTeam
   echo "</td><td>";
   echo '<input type="checkbox" id="'.$user["UserID"].'_irteam" name="IRTeam"'.$onclick;
   if($user['IRTeam'] == '1')
      echo " checked ";
   echo '/>';

   //Customer Rep
   echo "</td><td>";
   echo '<input type="checkbox" id="'.$user["UserID"].'_cr" name="CustomerRep"'.$onclick;
   if($user['CustomerRep'] == '1')
      echo " checked ";
   echo '/>';
   echo "</td>";
   echo '<td>';
   echo '<input id="'.$user["UserID"].'_save" class="save savebuttons" type="submit" name="Save" value="Save" onclick="submit('."'".$user["UserID"]."'".')"/>';
   echo '</td>';
   echo "</tr>";
}

?>
</table>
